from apscheduler.executors.asyncio import AsyncIOExecutor
from apscheduler.jobstores.redis import RedisJobStore
from apscheduler.schedulers.asyncio import AsyncIOScheduler
from pytz import timezone


def init_scheduler(apscheduler_redis_config, tz="Asia/Shanghai"):
    jobstores = {
        "default": RedisJobStore(**apscheduler_redis_config)
    }

    executors = {
        "default": AsyncIOExecutor()
    }
    scheduler = AsyncIOScheduler(jobstores=jobstores, executors=executors, timezone=timezone(tz))
    scheduler.start()
    return scheduler